#可视化窗口
from tkinter import *

import cv2

from face3 import face3Data
from face4 import face4Data
from face5 import face5Data
from face6 import face6Data
import face7

root = Tk()
root.title("人脸识别系统")
root.geometry("400x500")
#
potho=PhotoImage(file="img/bizhi.png")
bg=Label(root,image=potho)
bg.place(relx=0,rely=0,relheight=1,relwidth=1)
#定义文本组件
lable1=Label(root,text="人脸识别工具",font=50,fg="blue",bg="pink")
#停靠lable1.pack(side=TOP)
lable1.place(relx=0.213,rely=0.05,relwidth=0.4,relheight=0.1,anchor='c')
lable2=Label(root,text="功能区",font=20,fg="green",bg="yellow")
lable2.place(relx=0.5,rely=0.15,relwidth=0.2,relheight=0.05,anchor='c')
#button1
btn1=Button(root,text="录入人脸数据",font=10,fg="blue",bg="light blue",activebackground="gray",bd=10,command=face3Data)
btn1.place(relx=0.5,rely=0.25,relwidth=0.4,relheight=0.1,anchor='c')
#2
btn2=Button(root,text="清洗数据",font=10,fg="blue",bg="light blue",activebackground="gray",bd=10, command=face4Data)
btn2.place(relx=0.5,rely=0.4,relwidth=0.3,relheight=0.1,anchor='c')
#3
btn3=Button(root,text="储存数据",font=10,fg="blue",bg="light blue",activebackground="gray",bd=10,command=face5Data)
btn3.place(relx=0.5,rely=0.55,relwidth=0.3,relheight=0.1,anchor='c')
#4
btn4=Button(root,text="识别人脸",font=10,fg="blue",bg="light blue",activebackground="gray",bd=10,command=face6Data)
btn4.place(relx=0.5,rely=0.7,relwidth=0.3,relheight=0.1,anchor='c')

#输入框组件
inp1=Entry(root,font=20)
inp1.place(relx=0.5,rely=0.85,relwidth=0.4,relheight=0.1,anchor='c')
# 查询按钮点击事件处理函数
def on_button_click():
    person_name = inp1.get()
    images = face7.get_image_by_name(person_name)

    if images:
        for i, img in enumerate(images):
            print(f"显示 {person_name} 的第 {i + 1} 张图片")
            cv2.imshow(f"{person_name}'s Image {i + 1}", img)
            cv2.waitKey(0)
            cv2.destroyAllWindows()
    else:
        print("没有找到对应的图片。")
# 修改 btn5 的 command 参数为 on_button_click 函数
btn5 = Button(root, text="查询", font=5, fg="red", bg="light blue", activebackground="gray", bd=5,command=on_button_click)
btn5.place(relx=0.5, rely=0.95, relwidth=0.15, relheight=0.07, anchor='c')
#加载窗口
root.mainloop()